package net.bolue.sysmng.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.bolue.console.model.BusiBase;
import net.bolue.sysmng.db.DbOpUtil;
import net.bolue.sysmng.exception.BolueException;
import net.bolue.sysmng.tblbean.DbopResMap;
import net.bolue.sysmng.tblbean.UpdRes;
import net.bolue.sysmng.tblbean.UpdTabPage;
import net.bolue.web.report.RepConstants;

/**
 * 更新资源业务
 * @author Administrator
 *
 */
public class UpdResModel extends BusiBase{

	public UpdResModel() {
		super();
	}

	public UpdResModel(HttpServletRequest request) {
		super(request);
	}

	/**
	 * 获得更新资源
	 * @param subSys
	 * @param updateId
	 * @return
	 * @throws BolueException
	 */
	public UpdRes getUpdRes(String subSys,String updateId) throws BolueException{
		Map<String,Object> whereMap = new HashMap<String,Object>();
		whereMap.put("SUBSYS", subSys);
		whereMap.put("UPDATEID", updateId);
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		UpdRes updRes = dbOpUtil.getOne(UpdRes.class, "st_updres", null, whereMap);
		return updRes;
	}
	
	/**
	 * 获得更新资源映射
	 * @param subSys
	 * @param repId
	 * @return
	 * @throws BolueException
	 */
	public DbopResMap getUpdResMap(String subSys,String repId) throws BolueException{
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		Map<String,Object> whereMap = new HashMap<String,Object>();
		whereMap.put("REPID", repId);
		whereMap.put("SUBSYS", subSys);
		whereMap.put("DBOPTYPE", 1);
		DbopResMap dbopResMap = dbOpUtil.getOne(DbopResMap.class, "st_dbopresmap", null, whereMap);
		return dbopResMap;
	}
	
	/**
	 * 获得更新资源标签页
	 * @param subSys
	 * @param updateId
	 * @return
	 * @throws BolueException
	 */
	public List<UpdTabPage> getTabPage(String subSys,String updateId)throws BolueException{
		Map<String,Object> whereMap = new HashMap<String,Object>();
		whereMap.put("UPDATEID", updateId);
		whereMap.put("SUBSYS", subSys);
		Map<String,String> orderMap = new HashMap<String,String>();
		orderMap.put("PAGENO", "ASC");
		DbOpUtil dbOpUtil = new DbOpUtil(RepConstants.SYSMNG_SUBSYS_KEY);
		List<UpdTabPage> list = dbOpUtil.query(UpdTabPage.class, "st_updtabpage", null, whereMap, orderMap);
		return list;
	}
}
